﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace DNT.RavenQA.Core.Extensions
{
    public static class EnumerableExtensions
    {
        public static Boolean IsEmpty<T>(this IEnumerable<T> source)
        {
            source.EnsureIsNotNull("source");

            return !source.Any();
        }

        public static Boolean IsNotEmpty<T>(this IEnumerable<T> source)
        {
            return !source.IsEmpty();
        }

        public static Boolean IsNotNullOrEmpty<T>(this IEnumerable<T> source)
        {
            return source.IsNotNull() && source.IsNotEmpty();
        }

        public static void EnsureIsNoMatch<T>(this IEnumerable<T> source, Func<T, bool> predicate)
        {
            Object sequenceElement = source.SingleOrDefault(predicate);
            sequenceElement.EnsureIsNull("sequenceElement");
        }
    }
}